substitute character

I'm challenged by the need to replace hyphens in Object Level with decimals for compatibility with another app. So far I haven't been successful.
Change 3.1.0-2 to 3.1.0.2, and 3.1.0-2.1.0-1 to 3.1.0.2.1.0.1. Any suggestions are appreciated.
steelemic - Thu Feb 02 18:48:41 EST 2012

Re: substitute character
rain_bow - Thu Feb 02 19:18:43 EST 2012

Search for replace in this forum and you will find some dxl for this simple replace.

Re: substitute character
SystemAdmin - Thu Feb 02 19:27:21 EST 2012

Try the following code snippet as an example - this snippet also gets rid of the leading zero character which is redundant if all you're trying to do is convert the Object Number into a paragraph number.
 

Object o = current
 
string paraNum = number( o )
 
// Set up regular expression to look for "0-".  The "(.*)" bits will return the parts of the
// matched string on each side of the "0-"
 
Regexp findZeroDash = regexp "(.*)0-(.*)"
 
while ( findZeroDash paraNum ) {
 
      // If the regular expression was matched then concatenate the parts of the para num on
      // each side of "0-"
 
      paraNum = paraNum[match 1] paraNum[match 2]
        }
 
print paraNum

 


Paul Miller
Melbourne, Australia

 

Re: substitute character
steelemic - Thu Feb 02 20:04:48 EST 2012

Rain_bow thank you.
Paul,
-E- DXL: <Line:17> incorrectly concatenated tokens
-E- DXL: <Line:17> undeclared variable (paraNummatch)

cannot figure out what paraNummatch should be/do. Tried paranum match 1 but still get the token error. Commented out the line and correctly get first character of Object Number. Suggestion?

Re: substitute character
steelemic - Thu Feb 02 20:08:37 EST 2012

steelemic - Thu Feb 02 20:04:48 EST 2012
Rain_bow thank you.
Paul,
-E- DXL: <Line:17> incorrectly concatenated tokens
-E- DXL: <Line:17> undeclared variable (paraNummatch)

cannot figure out what paraNummatch should be/do. Tried paranum match 1 but still get the token error. Commented out the line and correctly get first character of Object Number. Suggestion?

Ignore previous response. I see the code send by email differs from what appears in forum.

Re: substitute character
SystemAdmin - Thu Feb 02 20:41:40 EST 2012

steelemic - Thu Feb 02 20:04:48 EST 2012
Rain_bow thank you.
Paul,
-E- DXL: <Line:17> incorrectly concatenated tokens
-E- DXL: <Line:17> undeclared variable (paraNummatch)

cannot figure out what paraNummatch should be/do. Tried paranum match 1 but still get the token error. Commented out the line and correctly get first character of Object Number. Suggestion?

The script as copied from my post above and pasted straight into the DXL Editor runs fine for me on DOORS v9.2.0.3 (build 92412) - what version are you running?

Although I note that the error you have reported suggests that the square braces that are around each of the two match() functions are missing - maybe you don't see those square braces in your browser so this could be a browser issue or a copy-n-paste issue. Also, there's been some fiddling about with how the DXL Regular Expressions work in DOORS over past previous versions.

The match() function is used to carve out specific chunks of the regular expression, the delimiter between chunks is loosely the literal character or text strings that you're searching for. Hard to explain here, I would recommend you have a look at the DXL reference Manual under the heading path "General language facilities">"Regular Expressions">"Match" - there's an example code snippet to help demonstrate how the match() function works.

Regular Expressions are a specialist area to which I only occasionally dabble in and often get PERL or UNIX script writers to help as Regular Expression definitions are a staple for these people (I believe copious amounts of Coca Cola, Pizza and late nights help!).
Paul Miller
Melbourne, Australia

Re: substitute character
SystemAdmin - Thu Feb 02 20:45:24 EST 2012

SystemAdmin - Thu Feb 02 20:41:40 EST 2012
The script as copied from my post above and pasted straight into the DXL Editor runs fine for me on DOORS v9.2.0.3 (build 92412) - what version are you running?

Although I note that the error you have reported suggests that the square braces that are around each of the two match() functions are missing - maybe you don't see those square braces in your browser so this could be a browser issue or a copy-n-paste issue. Also, there's been some fiddling about with how the DXL Regular Expressions work in DOORS over past previous versions.

The match() function is used to carve out specific chunks of the regular expression, the delimiter between chunks is loosely the literal character or text strings that you're searching for. Hard to explain here, I would recommend you have a look at the DXL reference Manual under the heading path "General language facilities">"Regular Expressions">"Match" - there's an example code snippet to help demonstrate how the match() function works.

Regular Expressions are a specialist area to which I only occasionally dabble in and often get PERL or UNIX script writers to help as Regular Expression definitions are a staple for these people (I believe copious amounts of Coca Cola, Pizza and late nights help!).


Paul Miller
Melbourne, Australia

Even though your follow up post was 4 minutes after your previous one - it didn't appear in my email until after I had attempted to answer the problem you reported - technology eh!


Paul Miller
Melbourne, Australia

Re: substitute character
steelemic - Mon Feb 06 12:21:29 EST 2012

Thank you for your help.
The following code worked. Two small changes to get behavior I was looking for.

// get Object Number
string paraNum = number ( obj )

// Set up regular expression to look for "0-". The "(.*)" bits will return the parts of the
// matched string on each side of the "0-"

Regexp findZeroDash = regexp "(.*)0-(.*)"

while ( findZeroDash paraNum ) {

// If the regular expression was matched then concatenate the parts of the para num on
// each side of "0-"
// Change "0-" to "0."
// example 1.0-1 becomes 1.0.1

paraNum = paraNummatch 1 "0." paraNummatch 2
}

display paraNum